﻿
$(function() {
    JSUtility.param.Options["InternalType"] = "0";
    JSUtility.param.ClassName = "OA.Bll.Project.ProjectQualityInfoPresenter";
    autoResize({ dataGrid: '#Grid', callback: Initlist });
    JSUtility.window_edit = $('#Add').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '添加项目质量管理信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 600,
        //  height: 520,
        closed: true,
        onOpen: function() {
            $('#Add').parent().css("left", "10%");
            $('#Add').parent().next().css("left", "10%");
            $('#Add').parent().next().css("top", "10%");
            $('#Add').parent().css("top", "10%");
        }
    });
    JSUtility.window_edit_form = $("#Add").find("form");
    // $("#")
    JSUtility.window_edit_title = "项目质量管理信息";
    $('#Add').show();
    comboboxInitial();
});

function comboboxInitial() {
    JSHelper.comboboxData("#DocumentField", '12');
    JSHelper.comboboxData("#QualityField", '13');
    $("#QualityFileType").combobox({
        onSelect: function(record) {
            if (record.value == "初设文件") {
                $("#QualityDesign").show();
                $("#WorkDrawring").hide();
            } else {
                $("#QualityDesign").hide();
                $("#WorkDrawring").show();
            }
        }
    });
    if (!self.parent.projectInfoManager) {
        JSHelper.combotreeProject('ProjectId',null,135);
    }
}

function Initlist(size) {
    if (self.parent.projectInfoManager) {
        JSUtility.param.Options["ProjectId"] = self.parent.parent.project_id;
        JSUtility.replenish = function() {
            $("#ProjectId").val(self.parent.parent.project_id);
        };
        $("#ProjectId").attr("readonly", "readonly");
    }
    JSUtility.param.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        tilte: '项目质量管理信息',
        iconCls: 'icon-save',
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        nowrap: true,
        striped: true,
        url: JSUtility.url,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        sortName: 'Id',
        sortOrder: 'desc',
        idField: 'Id',
        frozenColumns: [[{ title: '编号', field: 'Id', width: 50, sortable: true}]],
        columns: [[
                            { title: '项目编号', field: 'ProjectId', width: 80 },
                            { title: '项目名称', field: 'ProjectName', width: 100 },
                            { title: '内审问题状态', field: 'InnerAuditState', width: 120 },
                            { title: '内审问题关闭时间', field: 'InnerAuditTime', width: 100 },
                            { title: '文档专业', field: 'DocumentField', width: 100 },
                            { title: '链接地址', field: 'DocumentAddress', width: 120 },
                            { title: '记录时间', field: 'QualityTime', width: 100 },
                            { title: '文件类型', field: 'QualityFileType', width: 100 },
                            { title: '质量专业', field: 'QualityField', width: 100 },
                            { title: '文件册数', field: 'QualityFileVolumeCount', width: 80 },
                            { title: '检查类型', field: 'QualityCheckType', width: 100 }

                        ]],
        view: detailview,
        detailFormatter: function(rowIndex, rowData) {
            //多列只存储Text
            var doc = '<table id="gridview" cellpadding="0" cellspacing="0" ><tr>' +
            '<td style="width:120px;">内审问题总数量：</td><td> ' + (parseInt(rowData.InnerDisputeAuditCount) + parseInt(rowData.InnerGeneralAuditCount)
                + parseInt(rowData.InnerPrincipleAuditCount)) + '</td>' +
                '<td style="width:120px;">内审一般性问题数量：</td><td> ' + rowData.InnerGeneralAuditCount + '</td>' +
                    '<td style="width:120px;">内审原则性问题数量：</td><td>  ' + rowData.InnerPrincipleAuditCount + '</td>' +
                        '<td style="width:120px;">内审争议性问题数量：</td><td> ' + rowData.InnerDisputeAuditCount + '</td>' +
                            '<td style="width:120px;">外审一般性问题数量：</td><td> ' + rowData.OuterGeneralAuditCount + '</td>' +
                                '<td style="width:120px;">外审重要问题数量：</td><td> ' + rowData.OuterImportantAuditCount + '</td>' +
                                    '<td style="width:140px;">外审深度不够问题数量：</td><td> ' + rowData.OuterDeepAuditCount + '</td>' +
                                        '</tr>' +
                                            '<tr>' +
                                                '<td style="width:120px;">外审问题总数量：</td><td>  ' + (parseInt(rowData.OuterDeepAuditCount) + parseInt(rowData.OuterGeneralAuditCount) +
                                                    parseInt(rowData.OuterImportantAuditCount) + parseInt(rowData.OuterPrincipleAuditCount) + parseInt(rowData.OuterViolateSpecificationCount)) + '</td>' +
                                                '<td style="width:120px;">外审原则性问题数量：</td><td>  ' + rowData.OuterPrincipleAuditCount + '</td>' +
                                                    '<td style="width:150px;">外审违法规范强条问题数量</td><td>  ' + rowData.OuterViolateSpecificationCount + '</td>';
            if (rowData.QualityFileType == "初设文件") {
                doc += '<td style="width:90px;">初步设计说明书：</td><td> ' + rowData.QualityDesignSpecification + '</td>' +
                    '<td style="width:90px;">初步设计图纸：</td><td>  ' + rowData.QualityDesignDrawings + '</td>' +
                        '<td style="width:90px;">设计说明书及图纸：</td><td> ' + rowData.QualityDesignSpecificationDrawings + '</td>' +
                            '<td style="width:90px;">初步设计概算：</td><td>  ' + rowData.QualityDesignBudget + '</td>';
            } else {
                doc += '<td style="width:80px;">施工图册：</td><td> ' + ("第" + rowData.QualityVolume + "册" + rowData.QualityVolumeDescription) + '</td>' +
                    '<td style="width:80px;">施工图分册：</td><td>  ' + ("第" + rowData.QualityPartVolume + "分册" + rowData.QualityPartVolumnDescription) + '</td>' +
                        '<td style="width:80px;">施工图部分：</td><td> ' + ("第" + rowData.QualityChapter + "部分" + rowData.QualityChapterDescription) + '</td>';
            }
            doc += '</tr></table>';
            return doc;
        },
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: [
                    {
                        text: '添加',
                        iconCls: 'icon-add',
                        handler: JSUtility.add
                    }, '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function() {
                            JSUtility.update();
                            if ($("#QualityFileType").combobox("getValue") == "初设文件") {
                                $("#QualityDesign").show();
                                $("#WorkDrawring").hide();
                            } else {
                                $("#QualityDesign").hide();
                                $("#WorkDrawring").show();
                            }
                            JSHelper.conbotreeUpdateProject("ProjectId");
                        }
                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: JSUtility.del
                    }, '-',
                    {
                        text: '查询',
                        iconCls: 'icon-search',
                        handler: JSUtility.search
                    }
                  ]
    });
}